package udp;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

/**
 * 这是Udp版的简单翻译服务器
 */

public class UdpDictServer extends UdpEchoServer {

    private HashMap<String, String> hashMap = new HashMap<>();

    public UdpDictServer(int port) throws SocketException {
        super(port);

        hashMap.put("cat", "小猫");
        hashMap.put("dog", "小狗");
        hashMap.put("pig", "小猪");
    }

    @Override
    public String process(String request){
        return hashMap.getOrDefault(request, "该词无法被翻译");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer udpDictServer = new UdpDictServer(9090);
        udpDictServer.start();
    }
}
